package com.zuipin.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.entity.SysActionLog;
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.result.PageResult;
import com.zuipin.framework.result.Result;
import com.zuipin.service.ISysActionLogService;
import com.zuipin.util.Pagination;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 用户操作记录Controller
 * 
 * @ClassName: SysActionLogController
 * @Description: TODO
 * @author robot
 * @date 2017年09月147日 09:21:09
 */
@Api(value = "用户操作记录", description = "用户操作记录")
@RestController
@RequestMapping(value = "/sysActionLog")
public class  SysActionLogController {
	@Resource
	public ISysActionLogService sysActionLogService;

	
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	@ApiOperation(value = "根据主键查询用户操作记录", notes = "查询用户操作记录")
	public Result<SysActionLog> getSysActionLogById(@ApiParam(required = true, name = "id", value = "主键 自增长") @RequestParam Long id){
		SysActionLog sysActionLog = sysActionLogService.findById(id);
		Result<SysActionLog> result = new Result<SysActionLog>();
		if (sysActionLog != null) {
			result.setData(sysActionLog);
			result.setErrorCode(ErrorCode.SUCCESS);
		} else {
			result.setErrorCode(ErrorCode.ELSE);
		}
		return result;
	}
	
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ApiOperation(value = "新增用户操作记录", notes = "新增用户操作记录")
	@Valids({
		
		@Valid(name = "sysActionLog.operAccount",  maxLength = 64),
		@Valid(name = "sysActionLog.operName",  maxLength = 255),
		@Valid(name = "sysActionLog.operTarget",  maxLength = 64),
		@Valid(name = "sysActionLog.actionType",  maxLength = 12),
		@Valid(name = "sysActionLog.actionContent",  maxLength = 255),
		@Valid(name = "sysActionLog.createTime",  maxLength = 19),
		@Valid(name = "sysActionLog.delFlag",  maxLength = 3),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "sysActionLog.operAccount", value = "操作帐号", required = true, dataType = "operAccount", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.operName", value = "操作人姓名", required = true, dataType = "operName", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.operTarget", value = "操作目标", required = true, dataType = "operTarget", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.actionType", value = "操作类型",  dataType = "actionType", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.actionContent", value = "操作内容",  dataType = "actionContent", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.createTime", value = "",  dataType = "createTime", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.delFlag", value = "删除标识，1为删除，0为不删除",  dataType = "delFlag", paramType = "query"),
	})
	public Result<SysActionLog> insertSysActionLog(@Inject @ApiIgnore SysActionLog sysActionLog) {
		Result<SysActionLog> result = new Result<SysActionLog>();
		sysActionLogService.insert(sysActionLog);
		result.setData(sysActionLog);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ApiOperation(value = "根据主键修改用户操作记录", notes = "修改用户操作记录")
	@Valids({ 
		@Valid(name = "sysActionLog.id",  maxLength = 19),
		@Valid(name = "sysActionLog.operAccount",  maxLength = 64),
		@Valid(name = "sysActionLog.operName",  maxLength = 255),
		@Valid(name = "sysActionLog.operTarget",  maxLength = 64),
		@Valid(name = "sysActionLog.actionType",  maxLength = 12),
		@Valid(name = "sysActionLog.actionContent",  maxLength = 255),
		@Valid(name = "sysActionLog.createTime",  maxLength = 19),
		@Valid(name = "sysActionLog.delFlag",  maxLength = 3),
	})
	@ApiImplicitParams({
		@ApiImplicitParam(name = "sysActionLog.id", value = "主键 自增长", required = true, dataType = "id", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.operAccount", value = "操作帐号", required = true, dataType = "operAccount", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.operName", value = "操作人姓名", required = true, dataType = "operName", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.operTarget", value = "操作目标", required = true, dataType = "operTarget", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.actionType", value = "操作类型", dataType = "actionType", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.actionContent", value = "操作内容", dataType = "actionContent", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.createTime", value = "", dataType = "createTime", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.delFlag", value = "删除标识，1为删除，0为不删除", dataType = "delFlag", paramType = "query"),
	})
	public Result<SysActionLog> updateSysActionLog(@Inject @ApiIgnore SysActionLog sysActionLog) {
		Result<SysActionLog> result = new Result<SysActionLog>();
		sysActionLogService.update(sysActionLog);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/del", method = RequestMethod.DELETE)
	@ApiOperation(value = "根据主键删除用户操作记录", notes = "删除用户操作记录")
	public Result<SysActionLog> delSysActionLog( Long id) {
		Result<SysActionLog> result = new Result<SysActionLog>();
		sysActionLogService.delete(id);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/seach", method = RequestMethod.POST)
	@ApiOperation(value = "搜索用户操作记录SKU用户操作记录并分页", notes = "搜索用户操作记录并分页")
	@Valids({
		
		@Valid(name = "sysActionLog.operAccount",  maxLength = 64),
		@Valid(name = "sysActionLog.operName",  maxLength = 255),
		@Valid(name = "sysActionLog.operTarget",  maxLength = 64),
		@Valid(name = "sysActionLog.actionType",  maxLength = 12),
		@Valid(name = "sysActionLog.actionContent",  maxLength = 255),
		@Valid(name = "sysActionLog.createTime",  maxLength = 19),
		@Valid(name = "sysActionLog.delFlag",  maxLength = 3),
		@Valid(name = "page.pageNumber",  maxValue = 999),
		@Valid(name = "page.pageSize",  maxValue = 999),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "sysActionLog.operAccount", value = "操作帐号", required = true, dataType = "operAccount", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.operName", value = "操作人姓名", required = true, dataType = "operName", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.operTarget", value = "操作目标", required = true, dataType = "operTarget", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.actionType", value = "操作类型", dataType = "actionType", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.actionContent", value = "操作内容", dataType = "actionContent", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.createTime", value = "", dataType = "createTime", paramType = "query"),
		@ApiImplicitParam(name = "sysActionLog.delFlag", value = "删除标识，1为删除，0为不删除", dataType = "delFlag", paramType = "query"),
		@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
		@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"),
	})
	public Result<List<SysActionLog>> seachSysActionLog(@Inject @ApiIgnore SysActionLog sysActionLog,
			@Inject @ApiIgnore Pagination page) {
		PageResult<List<SysActionLog>> result = new PageResult<List<SysActionLog>>();
		result.setData(sysActionLogService.seachSysActionLog(sysActionLog, page));
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
}
